<template>
  <!-- 数据库信息卡片 -->
  <el-card class="db-card" shadow="never">
    <template #header>
      <div class="card-header">
        <el-icon><Coin /></el-icon>
        <span class="card-title-text">数据库</span>
        <el-tooltip :content="db.driverVersion" placement="top" effect="dark" :offset="8">
          <el-icon class="header-icon"><InfoFilled /></el-icon>
        </el-tooltip>
      </div>
    </template>
    <div class="connection-stats">
      <div class="stat-item">
        <div class="stat-value">{{ db.activeConnections }}</div>
        <div class="stat-label">活动连接</div>
      </div>
      <div class="stat-item">
        <div class="stat-value">{{ db.maxConnections }}</div>
        <div class="stat-label">最大连接</div>
      </div>
      <div class="stat-item">
        <div class="stat-value">{{ db.minConnections }}</div>
        <div class="stat-label">最小连接</div>
      </div>
    </div>
  </el-card>
</template>

<script setup>
import { ElCard, ElIcon, ElTooltip } from 'element-plus'
import { Coin, InfoFilled } from '@element-plus/icons-vue'

/**
 * 定义组件的 props
 * @param {Object} db - 包含数据库信息的对象
 */
defineProps({
  db: {
    type: Object,
    required: true,
    default: () => ({}),
  },
})
</script>

<style lang="scss" scoped>
@use '@/assets/styles/mixins.scss' as *;

.card-header {
  @include flex($align: center);
  font-weight: 500;

  .card-title-text {
    margin: 0 4px 0 8px;
  }

  .header-icon {
    color: var(--el-text-color-secondary);
    cursor: help;
    &:hover {
      color: var(--el-text-color-primary);
    }
  }
}

.connection-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  gap: 8px;

  .stat-value {
    font-size: 20px;
    font-weight: bold;
    color: var(--el-color-primary);
    font-family: 'Courier New', Courier, monospace;
  }
  .stat-label {
    font-size: 12px;
    color: var(--el-text-color-secondary);
    margin-top: 2px;
  }
}
</style>
